package Controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

/**
 * Servlet implementation class OrderController
 */
@WebServlet(urlPatterns="/OrderController")
public class OrderController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public OrderController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		/*System.out.println("fdsfsfs");
		JsonObject jsonObject=new JsonObject();
		jsonObject.addProperty("name","minh");
		jsonObject.addProperty("drink","cafe");
		response.getWriter().print(jsonObject);
		
		*/
		// gui du lieu json to form get request
		JsonArray jsonArray = new JsonArray();
		JsonObject jsonObject;
		JsonObject jsonResult = new JsonObject();
			jsonObject = new JsonObject();
			jsonObject.addProperty("name","minh");
			jsonObject.addProperty("drink","cafe");
			jsonArray.add(jsonObject);
			jsonObject = new JsonObject();
			jsonObject.addProperty("name","Hung");
			jsonObject.addProperty("drink","Cam ep");
			jsonArray.add(jsonObject);
		jsonResult.add("listCompanyType",jsonArray);
		response.getWriter().print(jsonResult);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//lay du lieu  tu request post
		String name =	request.getParameter("name");
		String drink = request.getParameter("drink");

		//gui lai form
		JsonObject json = new JsonObject();
		json.addProperty("name",name);
		json.addProperty("drink", drink);		
		response.getWriter().print(json);
		
		
	}

}
